<?php
class UserAction extends Action
{
    public function register()
    {
        if (!cookie('fcs_login')) {
            $this->display();
        }else{
            $this->error('您当前已经以'.cookie('fcs_login')['username'].'的身份登录！');
        }
    }

    public function check_register()
    {
        $User = D('User');
        if ($User->create()) {
            $result = $User->add();
            if ($result) {
                $this->success('注册成功!', 'personal');
            } else {
                $this->error('注册失败!');
            }
        } else {
            $this->error($User->getError());
        }
    }

    public function login()
    {
        if (!cookie('fcs_login')) {
            $this->display();
        }else{
            $this->error('您当前已经以'.cookie('fcs_login')['username'].'的身份登录！');
        }
    }

    public function check_login()
    {
        $username = $_POST['username'];
        $password = $_POST['password'];
        $User = D('User');
        $result = $User->where("username='$username'")->select();
        if ($result) {
            if ($password == $result[0]['password']) {
                $this->success('登录成功！', 'personal');
                cookie('fcs_login', array('username' => $username, 'password' => $password));
            }
        } else {
            $this->error('用户名错误！');
        }

    }

    public function personal()
    {
        if (!cookie('fcs_login')) {
            $this->error('请先登录！', 'login');
        } else {
            echo "NO";
        }
        $User = D('User');
        $result = $User->where('id=2')->select();
        $this->assign('info', $result);
        $this->display('', 'info');
    }
}